package com.app.teaware.bean;

import com.alibaba.fastjson.annotation.JSONField;
import com.app.teaware.util.UnitUtil;

import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Index;

import java.util.ArrayList;

import my.MathUtils;


public class BoxInfoListBean extends BaseListBean{
    private ArrayList<BoxInfoData> list = new ArrayList<BoxInfoData>();

    public ArrayList<BoxInfoData> getList() {
        return list;
    }

    public void setList(ArrayList<BoxInfoData> list) {
        this.list = list;
    }

    @JSONField(serialize = false)
    public void addListBean(BoxInfoListBean listbean) {
        if (listbean == null)
            return;
        if (this.getCurrentPage() == INIT_PAGE) {
            setList(listbean.getList());
        } else {
            if (list == null)
                list = new ArrayList<BoxInfoData>();
            list.addAll(listbean.getList());
        }
        setListBeanData(listbean);
    }

    //获得毛重
    public double getBwf(){
        double fRet = -1;   //返回值<0时，表示无相关内容
        if (list.size()>0){
            fRet = list.get(0).getBwf();    //???当对应json字段为null的情况时，暂未测试异常
            double cz = UnitUtil.getRatio(list.get(0).getBun(),"kg");
            boolean isSameUtil = cz == 0;
            if(isSameUtil){
                return fRet;
            }else {
                fRet = MathUtils.multiply(fRet,cz);
            }


        }
        return fRet;
    }

    //获得净重
    public double getBwt(){
        double fRet = -1;   //返回值<0时，表示无相关内容
        if (list.size()>0){
            fRet = list.get(0).getBwt();    //???当对应json字段为null的情况时，暂未测试异常
            double cz = UnitUtil.getRatio(list.get(0).getBun(),"kg");
            boolean isSameUtil = cz == 0;
            if(isSameUtil){
                return fRet;
            }else {
                fRet = MathUtils.multiply(fRet,cz);
            }
        }

        return fRet;
    }

    public BoxInfoData getBoxInfoByChoose(int position){
        return list.get(position);
    }
}
